package com.future.network

import android.app.Activity
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.future.network.annotation.Network
import com.future.network.info.CommonNetworkStateController
import com.future.network.info.NetworkController
import com.future.network.utiles.DebugLogs

class text : AppCompatActivity(), NetworkController {
    private lateinit var obj: CommonNetworkStateController
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        obj = object : CommonNetworkStateController(){

            override fun lostNet() {
                super.lostNet()
                DebugLogs.show("111网络丢失")
            }

            override fun wifi2mobile() {
                super.wifi2mobile()
                DebugLogs.show("111WiFi切换到移动")
            }

            override fun mobile2wifi() {
                super.mobile2wifi()
                DebugLogs.show("111移动切换到WiFi")
            }

            override fun netReconnecting() {
                super.netReconnecting()
                DebugLogs.show("111网络重连")
            }

            override fun currentNetwork(networkType: NetworkType) {
                super.currentNetwork(networkType)
                DebugLogs.show("111当前网络"+networkType)
            }
        }
        NetworkManager.get().registerObserver(obj)
        NetworkManager.get().registerObserver(this)
        NetWorkMonitorManager.get().registerObserver(this)

    }

    @Network(netType = NetworkType.AUTO)
    fun network1(networkType: NetworkType) {
        DebugLogs.show("$this===>" + networkType.toString())
    }

    override fun networkType(networkType: NetworkType) {
        DebugLogs.show("$this==>2" + networkType.toString())
    }

    override fun onDestroy() {
        super.onDestroy()
        NetworkManager.get().unRegisterObserver(this)
        NetworkManager.get().unRegisterObserver(obj)
        NetWorkMonitorManager.get().unRegisterObserver(this)
    }
}